
OverPanel = {};
local this = OverPanel;

local transform;
local gameObject;
local behaviour;

function OverPanel.New(overdata)
    this.overdata = overdata;
    panelMgr:CreatePanel("Over",nil);
end

function OverPanel.Awake(obj)
    gameObject = obj;
    transform = obj.transform;
    behaviour = transform:GetComponent("LuaBehaviour");

    for i=1,1 do
        local player = transform:Find("Player"..i);
        this.InitPlayer(player,this.overdata.results[i]);
    end

    this.restatBtn = transform:Find("restatBtn").gameObject;
    this.quitBtn = transform:Find("quitBtn").gameObject;

    behaviour:AddClick(this.restatBtn,this.OnRestatClick);
    behaviour:AddClick(this.quitBtn,this.OnQuitClick);
end

function OverPanel.InitPlayer(player,result)
    player:Find("name"):GetComponent("UILabel").text = result.username;
    player:Find("score"):GetComponent("UILabel").text = result.score;
    player:Find("addScore"):GetComponent("UILabel").text = result.score;
    local isLord = result.seatId == this.overdata.landlordId;
    log(player:Find("landlord").gameObject.name)
    player:Find("landlord").gameObject:SetActive(isLord);

    
    local container = player:Find("container");
    table.sort(result.pais);
    for i,paiId in ipairs(result.pais) do
        local card = ResourcesFactory.CreateCard(paiId);
        card.transform:SetParent(container,false);
        card.transform.localPosition =Vector3(i*60,0);
        card.panel.depth = 100+i;
    end
end

function OverPanel.OnRestatClick()
    log("点击继续")
    Network.Send(Protocal.ReqRestart);
end

function OverPanel.OnQuitClick()
    Network.Send(Protocal.ReqQuit);
end